package com.guofen.controller.cylj;

import com.guofen.pojo.KitchenwasteIncome;
import com.guofen.service.cylj.KitchenwasteIncomeService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api("厨余垃圾黑水虻就地处理站来料记录表")
public class KitchenwasteIncomeController {
    @Resource
    private KitchenwasteIncomeService kitchenwasteIncomeService;

    @ApiOperation("提交厨余垃圾黑水虻就地处理站来料记录")
    @PostMapping("/kitchenwaste/income/add")
    public boolean submitAllInfo(@RequestParam("incomeDate") String incomeDate,@RequestParam("incomeWeight") String incomeWeightstr,@RequestParam("bucketWeight") String bucketWeightstr,
                                 @RequestParam("waterWeight") String waterWeightstr,@RequestParam("impurityWeight") String impurityWeightstr,@RequestParam("incomeNetweight") String incomeNetweightstr,
                                 @RequestParam("feedWeight") String feedWeightstr,@RequestParam("cultivationWeight") String cultivationWeightstr, @RequestParam("throwWeight") String throwWeightstr,
                                 @RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        double incomeWeight = Double.parseDouble(incomeWeightstr);
        double bucketWeight = Double.parseDouble(bucketWeightstr);
        double waterWeight = Double.parseDouble(waterWeightstr);
        double impurityWeight = Double.parseDouble(impurityWeightstr);
        double incomeNetweight = Double.parseDouble(incomeNetweightstr);
        double feedWeight = Double.parseDouble(feedWeightstr);
        double cultivationWeight = Double.parseDouble(cultivationWeightstr);
        double throwWeight = Double.parseDouble(throwWeightstr);
        return kitchenwasteIncomeService.submitAllIndfo(new KitchenwasteIncome(incomeDate,incomeWeight,bucketWeight,waterWeight,impurityWeight,incomeNetweight,feedWeight,cultivationWeight,throwWeight,recorder,remark));
    }
    @ApiOperation("获取 当日 最新 一条记录")
    @GetMapping(value = "/kitchenwaste/income/getlast")
    public Result getlast(){
        return  ResultGenerator.genSuccessResult(kitchenwasteIncomeService.getlast());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/kitchenwaste/income/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(kitchenwasteIncomeService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/kitchenwaste/income/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name = "incomeDate", value = "日期", required = true) @RequestParam String incomeDate,
                         @ApiParam(name = "incomeWeight", value = "来料重（kg）", required = true) @RequestParam String incomeWeightstr,
                         @ApiParam(name = "bucketWeight", value = "桶重（kg）", required = true) @RequestParam String bucketWeightstr,
                         @ApiParam(name = "waterWeight", value = "水重（kg）", required = true) @RequestParam String waterWeightstr,
                         @ApiParam(name = "impurityWeight", value = "杂质重（kg）", required = true) @RequestParam String impurityWeightstr,
                         @ApiParam(name = "incomeNetweight", value = "来料净重（kg）", required = true) @RequestParam String incomeNetweightstr,
                         @ApiParam(name = "feedWeight", value = "进料重（kg）", required = false) @RequestParam String feedWeightstr,
                         @ApiParam(name = "cultivationWeight", value = "培育量（kg）", required = true) @RequestParam String cultivationWeightstr,
                         @ApiParam(name = "throwWeight", value = "丢弃量（kg）", required = true) @RequestParam String throwWeightstr,
                         @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks) {
        double incomeWeight = Double.parseDouble(incomeWeightstr);
        double bucketWeight = Double.parseDouble(bucketWeightstr);
        double waterWeight = Double.parseDouble(waterWeightstr);
        double impurityWeight = Double.parseDouble(impurityWeightstr);
        double incomeNetweight = Double.parseDouble(incomeNetweightstr);
        double feedWeight = Double.parseDouble(feedWeightstr);
        double cultivationWeight = Double.parseDouble(cultivationWeightstr);
        double throwWeight = Double.parseDouble(throwWeightstr);

        return ResultGenerator.genSuccessResult(kitchenwasteIncomeService.update(new KitchenwasteIncome(incomeDate,incomeWeight,bucketWeight,waterWeight,impurityWeight,incomeNetweight,feedWeight,cultivationWeight,throwWeight,null,remarks)));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/kitchenwaste/income/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(kitchenwasteIncomeService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(kitchenwasteIncomeService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
